package com.shoparc.maidenlane;

import java.util.ArrayList;

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

import com.shoparc.geo.Element;
import com.shoparc.geo.Quad;

public class PanelType1 extends Panel {
	Element glassPlane;
	Rotation planeRot;
	ArrayList<Quad>frame;

	PanelType1(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D p4) {
		super(p1, p2, p3, p4);
		ArrayList<Vector3D> gpArr = new ArrayList<Vector3D>();
		gpArr.add(new Vector3D(p1.getX(), p1.getY(), p1.getZ()));
		gpArr.add(new Vector3D(p2.getX(), p2.getY(), p2.getZ()));
		gpArr.add(new Vector3D(p3.getX(), p3.getY(), p3.getZ()));
		gpArr.add(new Vector3D(p4.getX(), p4.getY(), p4.getZ()));
		glassPlane = new Element(gpArr);
		
		

	}
	
	PanelType1(ArrayList<Vector3D> vertices) {
		super(vertices);
		ArrayList<Vector3D> gpArr = new ArrayList<Vector3D>();
		for(Vector3D v : vertices){
			gpArr.add(new Vector3D(v.getX(), v.getY(), v.getZ()));
		}
		
		glassPlane = new Element(vertices);
	
	}
	
	public void translate(Vector3D t){
		super.translate(t);
		glassPlane.translate(t);
	}
	
	public void rotate(Rotation r){
		super.rotate(r);
		
		//TODO this is currently broken
		for(Vector3D v:glassPlane.vertices){
			v.subtract(barycenter);
			r.applyTo(v);
			v.add(barycenter);
		}
	}
	
	public void scale(double x, double y, double z){
		super.scale(x,  y,  z);
		glassPlane.scale(x,  y,  z);
	}
	
	public void buildFrame(){
		frame = new ArrayList<Quad>();
		Vector3D p1, p2, p3, p4, pa, pb, pc, pd;
		p1 = vertices.get(0);
		p2 = vertices.get(1);
		p3 = vertices.get(2);
		p4 = vertices.get(3);
		pa = glassPlane.vertices.get(0);
		pb = glassPlane.vertices.get(1);
		pc = glassPlane.vertices.get(2);
		pd = glassPlane.vertices.get(3);
		Quad q1 = new Quad(p1, p2, pb, pa);
		Quad q2 = new Quad(p2, p3, pc, pb);
		Quad q3 = new Quad(p3, p4, pd, pc);
		Quad q4 = new Quad(p4, p1, pa, pd);
		frame.add(q1);
		frame.add(q2);
		frame.add(q3);
		frame.add(q4);
		
	}
	
	
	
	

}
